/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package game.platformer.levels;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
import game.platformer.Player;
import game.platformer.interfaces.MapScreen;
import game.platformer.platformer;
import org.anddev.andengine.engine.handler.IUpdateHandler;
import org.anddev.andengine.entity.primitive.Rectangle;
import org.anddev.andengine.entity.scene.background.SpriteBackground;
import org.anddev.andengine.entity.shape.Shape;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.extension.physics.box2d.PhysicsConnector;
import org.anddev.andengine.extension.physics.box2d.PhysicsFactory;
import org.anddev.andengine.extension.physics.box2d.PhysicsWorld;
import org.anddev.andengine.opengl.texture.Texture;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
/**
 *
 * @author cow
 */
public final class levelOne implements Level {
	//varblock--------------------
	private boolean loaded;
	levelExit rightExit;
	private int height, width;
	private levelDeathBox boundry;
	//textures--------------------
	Texture platformsT;
	TextureRegion wideGrassTR, halfGrassTR, halfDirtTR;
	Texture backgroundT;
	TextureRegion backgroundTR;
	//platforms-------------------
	levelPlatform pOne, pTwo;
	//----------------------------
	public levelOne(platformer game){
		//initiailze level data
		height = 480;
		width = 720;
		loaded = false;
	}
	//manips-------------------------------------
	public int getHeight(){
		return height;
	}
	public int getWidth(){
		return width;
	}
	//-------------------------------------------
	//inherited----------------------------------
	/**
	 * loads the level onto the map screen.
	 *
	 * @param entranceX players entrance location
	 * @param entranceY players entrance location
	 */
	public void loadLevel(int entranceX, int entranceY){
		//dont load teh level twice
		if(loaded){
			return;
		}

		//references------------------------
		grassTextureSet gtex = platformer.getLevelManager().getGrassTexSet();
		MapScreen scr = platformer.getScreenManager().getMapScreen();
		PhysicsWorld pw = platformer.getPhysicsWorld();
		//----------------------------------

		//setup the platforms
		pOne = new levelPlatform(gtex.getDirtBasWide(), gtex.getRockDecWide(), 110, 310);
		pTwo = new levelPlatform(gtex.getDirtBasWide(), gtex.getGrassDecWide(), 360, 550);

		//place platforms
		pOne.place();
		pTwo.place();

		//death box--------------------
		boundry = new levelDeathBox(1000, 900);          //create the box so be 100x900
		boundry.setLastEntryPoint(entranceX, entranceY); //tell is where to place the player if he leaves
		boundry.place();                                 //put the box onto the screen
		//-----------------------------

		//backbround
		Sprite sTemp = new Sprite(0, 0, gtex.getBackground());
		scr.setBackground(new SpriteBackground(sTemp));

		//place the exits
		rightExit = new levelExit(360, 520, 100, 100, 1);//exit location, next level entrance location, levelID
		rightExit.place();

		//load the player
		Player.getPlayer().place(entranceX, entranceY);

		loaded = true;
	}
	/**
	 * this function loads all the textures and texture regions that
	 * the level will display.  It does not create the platforms.
	 * It is called by the leel manager.
	 */
	public void loadTextures(){
	}
	public boolean isLoaded(){
		return loaded;
	}
	public void unloadLevel(){
		//references-------------------
		final MapScreen scr = platformer.getScreenManager().getMapScreen();
		//-----------------------------

		scr.removePlatform(pOne);
		scr.removePlatform(pTwo);
		scr.removeEntity(rightExit);
		scr.removeEntity(boundry);

		loaded = false;
	}
	//-------------------------------------------
	public boolean colidesWithPlatform(Sprite colideable){
		if(pOne.getSpriteRep().collidesWith(colideable)){
			return true;
		}
		if(pTwo.getSpriteRep().collidesWith(colideable)){
			return true;
		}
		return false;
	}
}
